package com.zhubayi.shirodb.controller;

import com.zhubayi.shirodb.utils.VerifyCodeUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author zhubayi
 */
@Controller
public class TestController {
    @GetMapping("/index")
    public String toIndex(){
        return "index";
    }
    @GetMapping("toLogin")
    public String toLogin(){
        return "login";
    }
    @GetMapping("toRegister")
    public String toRegister(){
        return "register";
    }
    @GetMapping("getImage")
    public void getImage(HttpSession session, HttpServletResponse response) throws IOException {
        //生成验证码
        String code = VerifyCodeUtils.generateVerifyCode(4);
        //验证码放入session
        session.setAttribute("code",code);
        //验证码存入图片
        ServletOutputStream os = response.getOutputStream();
        response.setContentType("image/png");
        VerifyCodeUtils.outputImage(220,60,os,code);
    }
}
